﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>退货通知单查询结果</title>
    <link href="//unpkg.com/layui@2.10.1/dist/css/layui.css" rel="stylesheet">
    <style>
        .result-container {
            padding: 30px;
        }

        .layui-table {
            width: 100%;
            max-width: 1000px;
            margin: 0 auto;
            border: 1px solid #e6e6e6;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            border-collapse: separate;
            border-spacing: 0 8px;
        }

            .layui-table thead th {
                background-color: #f8f9fa;
                padding: 15px;
                text-align: center;
                border: 2px solid #e6e6e6;
                font-weight: 600;
                color: #2c3e50;
            }

            .layui-table tbody tr {
                background-color: #fff;
                transition: all 0.3s;
            }

                .layui-table tbody tr:hover {
                    transform: translateY(-2px);
                }

            .layui-table td {
                border: 1px solid #e6e6e6;
                padding: 15px;
                vertical-align: middle;
                word-wrap: break-word;
            }
    </style>
</head>

<body>
    <a href="http://localhost:5223/sales/Getreturn_notice_main">返回页面</a>
    <div class="result-container" id="resultContainer"></div>

    <script src="//unpkg.com/layui@2.10.1/dist/layui.js"></script>
    <script>
        layui.use(['layer', 'jquery'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;

            // 日期格式化函数：将日期转为 YYYY-MM-DD 格式
            function formatDate(dateStr) {
                if (!dateStr) return '';
                const date = new Date(dateStr);
                const year = date.getFullYear();
                const month = String(date.getMonth() + 1).padStart(2, '0');
                const day = String(date.getDate()).padStart(2, '0');
                return `${year}-${month}-${day}`;
            }

            // 仓库数字转换函数
            function convertWarehouseId(warehouse_id) {
                if (warehouse_id ==1) {
                    return '成品仓';
                }
                return warehouse_id;
            }

            // 业务状态转换函数
            function convertWarehouse(business_status_id) {
                if (business_status_id ==1) {
                    return '正常';
                }
                if (business_status_id ==2) {
                    return '挂起';
                }
                return business_status_id;
            }




            // 获取 URL 中的 document_code 参数
            var urlParams = new URL(window.location.href);
            var document_code = urlParams.searchParams.get('document_code');

            if (!document_code) {
                layer.msg('参数错误', { icon: 2 });
                return;
            }

            // 发起查询请求
            $.ajax({
                url: `@ViewBag.BaseUrl/T7/Sales/Getreturn_notice_main?document_code=${document_code}`,
                type: 'GET',
                success: function (res) {
                    if (res.code === 0 && res.data && res.data.length > 0) {
                        var dataList = res.data;
                        var content = `<table class="layui-table">
                                                            <thead>
                                                                <tr>
                                                                    <th>单据编码</th>
                                                                    <th>业务类型</th>
                                                                    <th>仓库</th>
                                                                    <th>单据日期</th>
                                                                    <th>备注信息</th>
                                                                    <th>操作员</th>
                                                                    <th>客户名称</th>
                                                                    <th>单据状态</th>
                                                                    <th>审核员</th>
                                                                    <th>退货原因</th>
                                                                    <th>业务状态</th>
                                                                    <th>审核日期</th>
                                                                    <th>处理方式</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>`;
                        dataList.forEach(function (data) {
                            content += `
                                                        <tr>
                                                                    <td>${data.document_code}</td>
                                                                    <td>${data.business_type_id}</td>
                                                                    <td>${convertWarehouseId(data.warehouse_id)}</td>
                                                                    <td>${formatDate(data.document_date)}</td>
                                                                    <td>${data.remark}</td>
                                                                     <td>${data.operators}</td>
                                                                    <td>${data.customer_name}</td>
                                                                    <td>${data.document_status}</td>
                                                                    <td>${data.auditor}</td>
                                                                    <td>${data.return_reason_code}</td>
                                                                    <td>${convertWarehouse(data.business_status_id)}</td>
                                                                    <td>${formatDate(data.audit_date)}</td>
                                                                    <td>${data.handling_method_code}</td>
                                                        </tr>
                                                    `;
                        });
                        content += `</tbody></table>`;
                        $('#resultContainer').html(content);
                    } else {
                        layer.msg('查询失败：' + (res.msg || '无数据返回'), { icon: 2 });
                    }
                },
                error: function (xhr) {
                    layer.msg('网络请求失败：' + xhr.status, { icon: 2 });
                }
            });
        });
    </script>
</body>

</html>